package com.shuoyue.appdepends.base;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * BaseFragment
 */
public abstract class BaseFragment extends Fragment {

    public FragmentActivity mActivity;
    protected View mContentView;
    public Context mContext;
    public Unbinder unbinder;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        Log.i("fragment"+ this.getId() , "onCreate");
        super.onCreate(savedInstanceState);
        initParams(getArguments());
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.i("fragment"+ this.getId() , "onCreateView");
        mContentView = inflater.inflate(getLayoutId(), container, false);
        unbinder = ButterKnife.bind(this, mContentView);
        mActivity = getActivity();
        mContext = getContext();

        initView();
        return mContentView;
    }

    public abstract void initParams(Bundle bundle);

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        Log.i("fragment"+ this.getId() , "onActivityCreated"+this.getId());
        super.onActivityCreated(savedInstanceState);
        initData();
    }


    @Override
    public void onDestroyView() {
        Log.i("fragment"+ this.getId() , "onDestroyView"+this.getId());
        unbinder.unbind();
        super.onDestroyView();

    }

    @Override
    public void onPause() {
        Log.i("fragment"+ this.getId() , "onPause"+this.getId());
        super.onPause();
    }

    @Override
    public void onAttach(@NonNull Context context) {
        Log.i("fragment"+ this.getId() , "onAttach");
        super.onAttach(context);
    }

    @Override
    public void onStart() {
        Log.i("fragment"+ this.getId() , "onStart");
        super.onStart();
    }

    @Override
    public void onResume() {
        Log.i("fragment"+ this.getId() , "onResume");
        super.onResume();
    }

    @Override
    public void onStop() {
        Log.i("fragment"+ this.getId() , "onStop");

        super.onStop();
    }

    @Override
    public void onDetach() {
        Log.i("fragment"+ this.getId() , "onDetach");

        super.onDetach();
    }

    @Override
    public void onDestroy() {
        Log.i("fragment"+ this.getId() , "onDestroy");
        super.onDestroy();
    }

    protected abstract int getLayoutId();

    protected abstract void initView();

    protected void initData() {
    }

    public View getContentView() {
        return mContentView;
    }
}